const mongoose = require("mongoose");

const dbPath = 'mongodb://47.98.138.57:27018/HCSGroupDiary'; // http://47.98.138.57:27018/HCSGroupDiary

mongoose.connect(dbPath); // 连接数据库

const db = mongoose.connection;

const userModel = require("./model/user.js")

db.on("error" , (err)=>{
    console.log("数据库连接失败");
    process.exit(1); // 中断程序执行
})

db.on("open" , async (err)=> {
    console.log("数据库连接成功");
    let user = await userModel.findOne({ username : "HCS"});
    if(!user){
        await userModel.create({
            username : "HCS",
            password:"123456",
            atLoneliness:false,
            tel:"123456",
            headphoto:"/static/headphoto/default.webp",
            email:"123@qq.com"
        })
    }
})